<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>点碰撞检测，像素级判断</title>
<script type="text/javascript"  src="../../flash/FlashCore.js"></script>
<script type="text/javascript"  src="../../flash/JSTweener.js"></script>
<!---->
 <script type="text/javascript" src="../../flash/geom/Point.js"></script> 
 <script type="text/javascript" src="../../flash/geom/Rectangle.js"></script> 
 <script type="text/javascript" src="../../flash/geom/Matrix.js"></script> 
 <!---->
 <script type="text/javascript" src="../../flash/ui/Mouse.js"></script> 
 <script type="text/javascript" src="../../flash/ui/Keyboard.js"></script> 
<!---->
 <script type="text/javascript" src="../../flash/events/Event.js"></script> 
 <script type="text/javascript" src="../../flash/events/EventDispatcher.js"></script> 
 <script type="text/javascript" src="../../flash/events/KeyboardEvent.js"></script> 
 <script type="text/javascript" src="../../flash/events/MouseEvent.js"></script> 
 <script type="text/javascript" src="../../flash/events/ProgressEvent.js"></script> 
 <script type="text/javascript" src="../../flash/events/TimerEvent.js"></script> 
 <script type="text/javascript" src="../../flash/events/IOErrorEvent.js"></script> 
<!---->
 <script type="text/javascript" src="../../flash/net/URLVariables.js"></script> 
 <script type="text/javascript" src="../../flash/net/URLRequest.js"></script> 
 <script type="text/javascript" src="../../flash/net/URLRequestMethod.js"></script> 
 <script type="text/javascript" src="../../flash/net/URLLoaderDataFormat.js"></script> 
 <script type="text/javascript" src="../../flash/net/URLLoader.js"></script> 
 
  <script type="text/javascript" src="../../flash/resource/ResVO.js"></script> 
 <script type="text/javascript" src="../../flash/resource/ResLoadedEvent.js"></script> 
 <script type="text/javascript" src="../../flash/resource/ResProgressEvent.js"></script> 
 <script type="text/javascript" src="../../flash/resource/ResPool.js"></script> 

<script type="text/javascript"  src="../../flash/display/DisplayObject.js"></script>
<script type="text/javascript"  src="../../flash/display/InteractiveObject.js"></script>
<script type="text/javascript"  src="../../flash/display/DisplayObjectContainer.js"></script>
<script type="text/javascript"  src="../../flash/display/Stage.js"></script>
<script type="text/javascript"  src="../../flash/display/BitmapData.js"></script>
<script type="text/javascript"  src="../../flash/display/Bitmap.js"></script>
<script type="text/javascript"  src="../../flash/display/Loader.js"></script>
<script type="text/javascript"  src="../../flash/display/Graphics.js"></script>
<script type="text/javascript"  src="../../flash/display/Shape.js"></script>
<script type="text/javascript"  src="../../flash/display/Sprite.js"></script>
<script type="text/javascript"  src="../../flash/display/MovieClip.js"></script>
<script type="text/javascript"  src="../../flash/display/MovieClip2.js"></script>
<script type="text/javascript"  src="../../flash/display/SimpleButton.js"></script>

<script type="text/javascript"  src="../../flash/text/TextBaseline.js"></script>
<script type="text/javascript"  src="../../flash/text/TextFieldAlign.js"></script>
<script type="text/javascript"  src="../../flash/text/TextField.js"></script>

<script type="text/javascript"  src="../../flash/animation/ActionVO.js"></script>
<script type="text/javascript"  src="../../flash/animation/AnimationEvent.js"></script>
<script type="text/javascript"  src="../../flash/animation/AnimationPlayMode.js"></script>
<script type="text/javascript"  src="../../flash/animation/Animation.js"></script>

<script type="text/javascript"  src="../../flash/utils/GlobalUtil.js"></script>
<script type="text/javascript"  src="../../flash/utils/Stats.js"></script>
<script type="text/javascript"  src="../../flash/utils/Timer.js"></script>
<script type="text/javascript" >

/**********************
此测试只能将项目放到服务器上测试，
因为浏览器安全原因，本地无法测试
******************/

//框架主程序入口
var core = new FlashCore();
core.setCanvas( document.getElementById("cav"));
core.setMouseEnabled(true);
core.start();

//对stage进行一些参数设置
var stage = FlashCore.stage;
//加载图片
var loader = new Loader();
var pic1 ;
var container = new Sprite();
//加载完成
function loadedHandler(event){
	loader.removeEventListener( Event.COMPLETE , loadedHandler) ;
	var bmd = event.getTarget().getContent().getBitmapData() ; //获取图片数据源
	pic1 = new Bitmap(bmd);
	pic1.setY(100);
	pic1.setX(100);
	pic1.setScaleX(1.4);
	pic1.setRotation(30);
	
	container.setX(50);
	container.addChild(pic1);
	stage.addChild(container);
}
loader.addEventListener( Event.COMPLETE , loadedHandler) ;
loader.load( new URLRequest("../res/egg.png") ) ;

function onEnterFrame(event){
	if(pic1){
		if( pic1.hitTestPointPixels( stage.getMouseX(),stage.getMouseY(),true )){
			document.getElementById("debug").innerHTML = "碰撞了";
		}else{
			document.getElementById("debug").innerHTML = "";
		}
	}
}
stage.addEventListener( Event.ENTER_FRAME , onEnterFrame);
</script>

</head>
<body>
<div id="debug"></div>
<canvas id="cav" width="500" height="400px" style="background-color: #000000 ;">你的浏览器不支持HTML5。</canvas>
</body>
</html>